const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const getCanvasConfig = info => {
  return {
    width: 670,
    height: 1250,
    clear: true,
    views: [{
      type: 'image',
      url: info.bg, // 背景图
      top: 0,
      left: 0,
      width: 670,
      height: 1250,
    }, {
      type: 'image',
      url: info.banner, // 狗狗封面
      top: 118,
      left: 32,
      width: 608,
      height: 437
    }, {
      type: 'text',
      content: info.textA, // 名字或品种的文案-左
      color: '#111111',
      fontSize: 32,
      textAlign: 'center',
      top: 636,
      left: 101,
      // left: 24,
      // width: 150,
    }, {
      type: 'text',
      content: info.textB, // 品种或颜色的文案-右
      color: '#111111',
      fontSize: 32,
      textAlign: 'center',
      top: 636,
      left: 281,
      // left: 205,
      // width: 150,
    }, {
      type: 'text',
      content: info.textC, // 悬赏或帮他回家文案
      color: '#111111',
      fontSize: 36,
      textAlign: 'center',
      top: 612,
      left: 510,
      // left: 421,
      // width: 210,
    }, {
      type: 'text',
      content: info.phone, // 联系方式
      color: '#333333',
      fontSize: 26,
      textAlign: 'right',
      top: 703,
      left: 638,
      // left: 340,
      // width: 300,
    }, {
      type: 'text',
      content: info.time, // 时间
      color: '#333333',
      fontSize: 26,
      textAlign: 'right',
      top: 759,
      left: 638,
      // left: 340,
      // width: 300,
    }, {
      type: 'text',
      content: info.ctx, // 详情描述
      color: '#333333',
      fontSize: 26,
      // textAlign: 'right',
      lineHeight: 32,
      breakWord: true,
      MaxLineNumber: 3,
      top: 857,
      left: 32,
      width: 606,
    }, {
      type: 'text',
      content: info.local, // 地点
      color: '#333333',
      fontSize: 26,
      textAlign: 'right',
      top: 980,
      left: 638,
      // left: 202,
      // width: 425,
    }, {
      type: 'image',
      url: info.qecode, // 二维码
      top: 1029,
      left: 42,
      width: 180,
      height: 180,
      borderRadius: 90,
    }, {
      type: 'image',
      url: info.logo.replace('http://', 'https://'), // 头像
      top: 1029,
      left: 265,
      width: 60,
      height: 60,
      borderRadius: 30,
    }, {
      type: 'text',
      content: info.name, // 名字
      color: '#471b08',
      fontSize: 28,
      // textAlign: 'right',
      top: 1044,
      left: 332,
      // left: 332,
      // width: 302,
    }, ]
  }
}

module.exports = {
  formatTime: formatTime,
  getCanvasConfig
}